import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:package_info/package_info.dart';
import 'package:provider/provider.dart';
import 'package:s_mankey/config/resource_mananger.dart';
import 'package:s_mankey/config/storage_manager.dart';
import 'package:s_mankey/config/router_config.dart';
import 'package:s_mankey/generated/I18n.dart';
import 'package:s_mankey/model/user_model.dart';
import 'package:s_mankey/provider/provider_manager.dart';
import 'package:s_mankey/view_model/locale_vm.dart';
import 'package:s_mankey/view_model/login_vmodel.dart';


void main() /*=> runApp(MyApp());*/ async {
  Provider.debugCheckInvalidValueType = null;
  WidgetsFlutterBinding.ensureInitialized(); //确定已经初始化完成.
  await StorageManager.init(); //加载全局信息
  return runApp(MyApp()); //在运行App前先完成上面的初始化.
}

class MyApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
        providers: providers,
        child: Consumer<LocaleVM>(
            builder: (context, localeModelDemo, child) {
          return MaterialApp(
            theme: ThemeData(
              splashColor: Colors.transparent, // 点击时的高亮效果设置为透明
              highlightColor: Colors.transparent, // 长按时的扩散效果设置为透明
              primaryColor: Colors.white, //主题颜色
            ),
            locale: localeModelDemo.locales,
            //路由委托
            onGenerateRoute: Router.generateRoute,
            //路由跳转委托
            initialRoute: RouterName.tabNav,
            //初始化的时候要加载哪个路由
            localizationsDelegates: [
              I18n.delegate, //国际化协议代理, 加载需要用到的本地化资源
              GlobalMaterialLocalizations.delegate, //提供本地化文字的字符串.
              GlobalWidgetsLocalizations.delegate, //文字方向
            ],
            supportedLocales: GeneratedLocalizationsDelegate()
                .supportedLocales, //添加语言包,第一个参数是地区,第二个参数是国家, 如果用户手机没有对应的国家,则使用相同地区的语言,都没有找到,则使用最前面的语言.
          );
        }));
  }
}
